<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>轮播图特效</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        ul {
            position: relative;
            list-style: none;
            width: 60000px;
            left: 0;
            transition: all 0.5s ease 0s;
        }

        ul li {
            float: left;
            width: 450px;
            height: 250px;
            background-color: red;
            text-align: center;
            line-height: 250px;
            font-size: 60px;
        }

        ul li:nth-child(2n) {
            background-color: yellow;
        }

        img {
            height: 250px;
            width: 450px;
        }

        #box {
            position: relative;
            border: 1px solid black;
            width: 452px;
            height: 252px;
            margin: 50px auto;
            overflow: hidden;
        }

        #left {
            position: absolute;
            width: 50px;
            height: 50px;
            left: 20px;
            top: 50%;
            margin-top: -25px;
            background-color: skyblue;
        }

        #right {
            position: absolute;
            width: 50px;
            height: 50px;
            right: 20px;
            top: 50%;
            margin-top: -25px;
            background-color: skyblue;
        }
    </style>
</head>

<body>
    <div id="box">
        <ul id="lb">
            <li>大</li>
            <li>帅</li>
            <li>哥</li>
            <li>在</li>
            <li>此</li>
            <li><img src="images/pan.jpg" alt=""></li>
        </ul>
        <div id="left"></div>
        <div id="right"></div>
    </div>
    <script>
        var box = document.getElementById('box');
        var lb = document.getElementById('lb');
        var left = document.getElementById('left');
        var right = document.getElementById('right');
        var yeshu = 0;
        var cl = lb.firstElementChild.cloneNode(true);
        var lock=true;
        lb.appendChild(cl);
        right.onclick = function () {
            if(!lock)return;
            lock=false;
            lb.style.transition = 'all 0.5s ease 0s'
            yeshu++;
            lb.style.left = yeshu * -450 + 'px';
            if (yeshu > 5) {
                setTimeout(function () {
                    yeshu = 0
                    lb.style.left = yeshu * -450 + 'px';
                    lb.style.transition = 'none';
                    
                }, 500)
            }
            setTimeout(function () {
                    lock=true;
                }, 500)

        }
        left.onclick = function () {
            if(!lock)return;
            lock=false;
            yeshu--;
            lb.style.left = yeshu * -450 + 'px';
            lb.style.transition = 'all 0.5s ease 0s'
            if (yeshu <0) {
                yeshu = 6;
                lb.style.left = 6 * -450 + 'px';
                lb.style.transition = 'none';
                setTimeout(
                    function(){
                        lb.style.transition = 'all 0.5s ease 0s'
                        yeshu=5;
                        lb.style.left = yeshu * -450 + 'px';
                    },0);
            
                }
                setTimeout(function () {
                    lock=true;
                }, 500)

            }
        
    </script>
</body>

</html>